﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace WpfApplication
{
    class Wiring : IPowerSignal, INotifyPropertyChanged
    {
        private int gauge;
        private double length;
        public double Voltage { get; set; }
        public double Current { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;

        public int Gauge {
            get
            {
                return gauge;
            }
            set
            {
                gauge = value;
                if(PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("Gauge"));
            }
        }
        public double Length
        {
            get
            {
                return length;
            }
            set
            {
                length = value;
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("Length"));
            }
        }

        //Gauge depends on current
        public void SetGauge()
        {
            if (this.Current > 6) this.Gauge = 22;
            else if (this.Current > 4) this.Gauge = 24;
            else if (this.Current > 3) this.Gauge = 26;
            else if (this.Current > 2) this.Gauge = 28;
            else this.Gauge = 30;
        }

        //Length must be lest than return value for Vdrop not exceed 0.5.
        public void SetLength()
        {
            if (this.Voltage > 24)
            {
                switch (this.Gauge)
                {
                    case 22: this.Length = 62.5; break;
                    case 24: this.Length = 39.5; break;
                    case 26: this.Length = 24.5; break;
                    case 28: this.Length = 15.5; break;
                    default:
                        this.Length = 9.5; break;
                }
            }
            else
                this.Length = 6;
        }
    }
}
